home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / UNIX.ZIP / VMSCRACK / VMSC.C < prev    next >
C/C++ Source or Header  |  1996-11-14  |  35KB  |  1,324 lines

  1. /****************************************************************************\
  2.  *                                                                          *
  3.  *  VMS Crack V1.0 security program                                         *
  4.  *                                                                          *
  5.  *  Coded by Davide Casale in June 1994                                     *
  6.  *   (email address : casale@pmn.it)                                        *
  7.  *  Coded and optimized by Mario Ambrogetti in June 1994                    *
  8.  *   (email address : s65710@galileo.polito.it)                             *
  9.  *  Original algorithm by Shawn Clifford in February 1993                   *
  10.  *   (email address : sysop@robot.nuceng.ufl.edu)                           *
  11.  *                                                                          *
  12. \****************************************************************************/
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <ctype.h>
  18. #include <time.h>
  19. #include <signal.h>
  20. #include "mytypes.h"
  21. #include "getopt.h"
  22. #include "sysuaf.h"
  23. #include "hpwd.h"
  24.  
  25. #if defined(__TURBOC__) || defined(__WATCOMC__)
  26.   #include <io.h>
  27. #endif
  28.  
  29. #define MAXBUF 2048                  /* maximun buffer input       */
  30. #define NPASS  32                    /* maxinum size password      */
  31. #define MASKWH 0x1FU                 /* mask for wheel             */
  32. #define AFF(BIT) (BIT)?"YES":"NO"    /* affirmative                */
  33. #define SALT_TEST 0x85F7U            /* test for proper encryption */
  34.  
  35. typedef struct user_p {
  36.  
  37.           char   *username;         /* username (loginid)                */
  38.           byte   passwd1[8];        /* Encrypted primary password        */
  39.           byte   passwd2[8];        /* Encrypted secondary password      */
  40.           word   passwd_salt;       /* Password encryption salt          */
  41.           byte   encr_algo1;        /* Encryption algorithm code - pass1 */
  42.           byte   encr_algo2;        /* Encryption algorithm code - pass2 */
  43.           struct user_p *next;      /* next username                     */
  44.  
  45.         } user_t;
  46.  
  47.  
  48. enum {VOCABULARY,SINGLE,USER,CREATE,LIST_ALL,LIST_ONE,TEST} opr=VOCABULARY;
  49.  
  50. int encrypt;             /* encryption algorithm        */
  51. int encryptions;         /* amount of encryptions       */
  52. int num_users=0;         /* number of users             */
  53. int debug=0;             /* debug mode                  */
  54. int quiet=0;             /* quiet mode                  */
  55. int skip=0;              /* skip user account sisabled  */
  56. dword comparisions;      /* comparisions password       */
  57. dword test_low;          /* low part of test hash       */
  58. dword test_high;         /* high part of test hash      */
  59. double elapsed=1.0;      /* time elapsed                */
  60. double report;           /* comparisions/elapsed        */
  61. double performance;      /* algorithm performance       */
  62. char *SYSUAF_name=NULL;  /* SYSUAF file name            */
  63. char *voc_name=NULL;     /* vocabulary name             */
  64. char *out_name=NULL;     /* out file name               */
  65. char *pass_name=NULL;    /* password name               */
  66. char *user_name=NULL;    /* username                    */
  67. FILE *fSYSUAF=NULL;      /* SYSUAF file                 */
  68. FILE *fvoc=NULL;         /* vocabulary file             */
  69. FILE *fout=NULL;         /* output file                 */
  70. time_t start_time;       /* start time encryption       */
  71. time_t end_time;         /* start time encryption       */
  72. UAF  user;               /* user in SYSUAF              */
  73.  
  74. char obuf[8];                 /* output buffer      */
  75. char pbuf[NPASS];            /* password buffer    */
  76. char ubuf[NPASS];            /* username buffer    */
  77. char usertest[NPASS];        /* username for test  */
  78. char passtest[NPASS];        /* password for test  */
  79. char read_passwd[NPASS]="";  /* last read password */
  80.  
  81. dscdescriptor outdsc = {sizeof(obuf),obuf};
  82. dscdescriptor pwddsc = {sizeof(pbuf),pbuf};
  83. dscdescriptor usrdsc = {sizeof(ubuf),ubuf};
  84.  
  85. static char *restore_name="RESTORE.DAT";  /* default restore name file */
  86. static char str_MODE[]="[mode]\n";
  87. static char str_SYSUAF[]="[SYSUAF]\n";
  88. static char str_OUT[]="[output]\n";
  89. static char str_VOCA[]="[vocabulary]\n";
  90. static char str_PASS[]="[password]\n";
  91. static char str_USER[]="[user]\n";
  92. static char str_LASTPASS[]="[last password]\n";
  93. static char str_voca[]="vocabulary";
  94. static char str_sing[]="single";
  95. static char str_user[]="user";
  96.  
  97. const char user_test[]="ALBATROS";
  98. const char passwd_test[]="THISISPASSWORDTEST";
  99.  
  100. byte hash_test[4][8]={{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
  101.                       {0xB1,0xC1,0xD7,0xA0,0x8C,0xD3,0x81,0xF3},
  102.                       {0x60,0xC6,0x2D,0x06,0xAF,0xA5,0x10,0x7C},
  103.                       {0x50,0xAF,0x82,0xD5,0x4D,0x14,0x60,0xBA}};
  104.  
  105. const char *wheel[4]={"\b/","\b-","\b\\","\b|"};
  106.  
  107. char buffer[MAXBUF];   /* buffer input */
  108.  
  109. /* function prototypes */
  110.  
  111. void print_title(FILE *);
  112. int  find_user(char *);
  113. int  find_passwd(char *);
  114. void print_record(int);
  115. void init_stat(void);
  116. void end_stat(void);
  117. void print_stat(FILE *);
  118. void strip_name(char *,char *,int);
  119. void print_bytes(byte *,int);
  120. void print_date(byte *);
  121. void print_hours(byte *);
  122. void print_days(char *,byte);
  123. void exit_fn(void);
  124. char *str_dup(const char *);
  125. void str_upr(char *s);
  126. static void sgn_fn(void);
  127.  
  128. typedef void (*fptr)();
  129.  
  130. int main(int argc,char *argv[])
  131. {
  132.   int  option;             /* option flag                 */
  133.   int  ind_wheel=0;        /* index wheel                 */
  134.   int  con_wheel=0;        /* counter wheel               */
  135.   user_t *first_user;      /* first user                  */
  136.   user_t *last_user;       /* last  user                  */
  137.   user_t *cur_user;        /* current user                */
  138.   user_t *pre_user;        /* precedent user              */
  139.   char *ps;
  140.  
  141.   if (atexit(exit_fn)) {
  142.  
  143.     fputs("Error: no space left to register the exit function.\n",stderr);
  144.     exit(EXIT_FAILURE);
  145.   }
  146.  
  147. #ifdef __WATCOMC__
  148.   signal(SIGBREAK,(fptr)sgn_fn);
  149. #else
  150.   signal(SIGFPE,(fptr)sgn_fn);
  151. #endif
  152.  
  153.   signal(SIGABRT,(fptr)sgn_fn);
  154.   signal(SIGILL ,(fptr)sgn_fn);
  155.   signal(SIGINT ,(fptr)sgn_fn);
  156.   signal(SIGSEGV,(fptr)sgn_fn);
  157.   signal(SIGTERM,(fptr)sgn_fn);
  158.  
  159.   while ((option=getopt(argc,argv,"?hHsualckdqtS:V:O:P:U:")) != EOF) {
  160.  
  161.     switch(option) {
  162.  
  163.       case 's':
  164.  
  165.         opr=SINGLE;
  166.         break;
  167.  
  168.       case 'u':
  169.  
  170.         opr=USER;
  171.         break;
  172.  
  173.       case 'a':
  174.  
  175.         opr=LIST_ALL;
  176.         break;
  177.  
  178.       case 'l':
  179.  
  180.         opr=LIST_ONE;
  181.         break;
  182.  
  183.       case 'c':
  184.  
  185.         opr=CREATE;
  186.         break;
  187.  
  188.       case 't':
  189.  
  190.         opr=TEST;
  191.         break;
  192.  
  193.       case 'k':
  194.  
  195.         skip=1;
  196.         break;
  197.  
  198.       case 'd':
  199.  
  200.         debug=1;
  201.         quiet=0;
  202.         break;
  203.  
  204.       case 'q':
  205.  
  206.         quiet=1;
  207.         debug=0;
  208.         break;
  209.  
  210.       case 'S':
  211.  
  212.         SYSUAF_name=str_dup(optarg);
  213.         break;
  214.  
  215.       case 'V':
  216.  
  217.         voc_name=str_dup(optarg);
  218.         break;
  219.  
  220.       case 'O':
  221.  
  222.         out_name=str_dup(optarg);
  223.         break;
  224.  
  225.       case 'P':
  226.  
  227.         pass_name=str_dup(optarg);
  228.         break;
  229.  
  230.       case 'U':
  231.  
  232.         user_name=str_dup(optarg);
  233.         break;
  234.  
  235.       case '?':
  236.       case 'h':
  237.       case 'H':
  238.       default:
  239.  
  240.         print_title(stdout);
  241.  
  242.         puts("VMSC [Options]\n");
  243.         puts("  Options :");
  244.         puts("    -?,-h,-H  : Show this help page.");
  245.         puts("    -s        : Single word mode.");
  246.         puts("    -u        : Single user mode.");
  247.         puts("    -a        : Look all user's record.");
  248.         puts("    -l        : Look a specific user's record.");
  249.         puts("    -c        : Create a namelist from a SYSUAF to use as words.");
  250.         puts("    -k        : Don't skip user account disabled.");
  251.         puts("    -t        : Test crypt result for proper encryption.");
  252.         puts("    -d        : Debug mode.");
  253.         puts("    -q        : Quiet mode.");
  254.         puts("    -S file   : Specific SYSUAF file.");
  255.         puts("    -V file   : Specific vocabulary file.");
  256.         puts("    -O file   : Specific output file.");
  257.         puts("    -P pass   : Specific password.");
  258.         puts("    -U name   : Specific username.");
  259.  
  260.         exit(EXIT_SUCCESS);
  261.  
  262.     } /* switch */
  263.  
  264.   } /* while */
  265.  
  266.   if (!quiet)
  267.     print_title(stdout);
  268.  
  269.  
  270.  
  271.  
  272.   if (opr!=TEST) {
  273.  
  274.     /* get SYSUAF file name */
  275.  
  276.     if (SYSUAF_name==NULL) {
  277.  
  278.       printf("SYSUAF name file : ");
  279.       gets(buffer);
  280.  
  281.       SYSUAF_name=str_dup(buffer);
  282.     }
  283.  
  284.     /* open file SYSUAF */
  285.  
  286.     if ((fSYSUAF=fopen(SYSUAF_name,"rb"))==NULL) {
  287.  
  288.       fprintf(stderr,"Can't open SYSUAF's file: %s\n",SYSUAF_name);
  289.       exit(EXIT_FAILURE);
  290.     }
  291.  
  292.     if (opr==SINGLE) {
  293.  
  294.       /* get password for check */
  295.  
  296.       if (pass_name==NULL) {
  297.  
  298.         printf("Password to check : ");
  299.         gets(buffer);
  300.         pass_name=str_dup(buffer);
  301.       }
  302.  
  303.       /* check for the null password */
  304.  
  305.       if (*pass_name=='\0') {
  306.  
  307.         fputs("Error: null password.\n",stderr);
  308.         exit(EXIT_FAILURE);
  309.       }
  310.  
  311.       /* check long password */
  312.  
  313.       if (strlen(pass_name)>31) {
  314.  
  315.         fputs("Error: password is more than 31 character long.\n",stderr);
  316.         exit(EXIT_FAILURE);
  317.       }
  318.     }
  319.  
  320.     if ((opr!=LIST_ALL) && (opr!=LIST_ONE)) {
  321.  
  322.       if ((opr!=CREATE) && (opr!=SINGLE)) {
  323.  
  324.         /* get vocabulary file name */
  325.  
  326.         if (voc_name==NULL) {
  327.  
  328.           printf("Vocabulary name file : ");
  329.           gets(buffer);
  330.  
  331.           voc_name=str_dup(buffer);
  332.         }
  333.  
  334.         /* open file vocabulary */
  335.  
  336.         if ((fvoc=fopen(voc_name,"r"))==NULL) {
  337.  
  338.           fprintf(stderr,"Can't read vocabulary file: %s\n",voc_name);
  339.           exit(EXIT_FAILURE);
  340.         }
  341.       }
  342.  
  343.       if ((opr==LIST_ONE) || (opr==USER)) {
  344.  
  345.         /* get username */
  346.  
  347.         if (user_name==NULL) {
  348.  
  349.           printf("Username : ");
  350.           gets(buffer);
  351.           user_name=str_dup(buffer);
  352.         }
  353.  
  354.         /* Check for the null username */
  355.  
  356.         if (*user_name=='\0') {
  357.  
  358.           fputs("Error: null username.\n",stderr);
  359.           exit(EXIT_FAILURE);
  360.         }
  361.  
  362.         /* check long password */
  363.  
  364.         if (strlen(user_name)>31) {
  365.  
  366.           fputs("Error: username is more than 31 character long.\n",stderr);
  367.           exit(EXIT_FAILURE);
  368.         }
  369.       }
  370.  
  371.       /* get output file name */
  372.  
  373.       if (out_name==NULL) {
  374.  
  375.         printf("Output name file : ");
  376.         gets(buffer);
  377.  
  378.         out_name=str_dup(buffer);
  379.       }
  380.  
  381.       /* open file output */
  382.  
  383.       if ((fout=fopen(out_name,"a"))==NULL) {
  384.  
  385.         fprintf(stderr,"Can't write output file: %s\n",out_name);
  386.         exit(EXIT_FAILURE);
  387.       }
  388.  
  389.     }
  390.  
  391.     if ((opr==LIST_ONE) || (opr==USER)) {
  392.  
  393.       str_upr(user_name);
  394.  
  395.       if (!quiet)
  396.         printf("\nFind username: %s\n",user_name);
  397.  
  398.       if ((num_users=find_user(user_name))==0) {
  399.  
  400.         fputs("Error: username not found.\n",stderr);
  401.         exit(EXIT_FAILURE);
  402.       }
  403.     }
  404.   }
  405.  
  406.   /* process operation */
  407.  
  408.   switch (opr) {
  409.  
  410.     case VOCABULARY:
  411.  
  412.       print_title(fout);
  413.  
  414.       if (!quiet)
  415.         puts("\nReading users");
  416.  
  417.       first_user=last_user=NULL;
  418.  
  419.       while (fread(&user,sizeof(user),1,fSYSUAF)) {
  420.  
  421.         if (skip || (!((L_Flags_0 *)(&user.Login_Flags_0))->user_account)) {
  422.  
  423.           strip_name(buffer,user.Username,NPASS);
  424.  
  425.           /* control encryption algorithm */
  426.  
  427.           if (user.Encr_algo1==0) {
  428.  
  429.             if (debug)
  430.               printf("%s * algorithm 0 *\n",buffer);
  431.  
  432.             continue;  /* while */
  433.           }
  434.  
  435.           if (debug)
  436.             puts(buffer);
  437.  
  438.           /* create in memory new user */
  439.  
  440.           if ((cur_user=(user_t *)malloc(sizeof(user_t)))==NULL) {
  441.  
  442.             fputs("Error: out of memory.\n",stderr);
  443.             exit(EXIT_FAILURE);
  444.           }
  445.  
  446.           /* initialize new user */
  447.  
  448.           cur_user->username=str_dup(buffer);
  449.           cur_user->passwd_salt=user.Passwd_salt;
  450.           memcpy(cur_user->passwd1,user.Passwd1,8);
  451.           memcpy(cur_user->passwd2,user.Passwd2,8);
  452.           cur_user->encr_algo1=user.Encr_algo1;
  453.           cur_user->encr_algo2=user.Encr_algo2;
  454.           cur_user->next=NULL;
  455.  
  456.           /* insert new user */
  457.  
  458.           if (first_user==NULL)
  459.             first_user=cur_user;
  460.           else
  461.             last_user->next=cur_user;
  462.  
  463.           last_user=cur_user;
  464.  
  465.           num_users++;
  466.         }
  467.         else
  468.           if (debug) {
  469.             strip_name(buffer,user.Username,NPASS);
  470.             printf("%s * User account is disabled *\n",buffer);
  471.           }
  472.  
  473.       } /* while */
  474.  
  475.       if (!quiet)
  476.         putchar('\n');
  477.  
  478.       init_stat();
  479.  
  480.       if (num_users!=0) {
  481.  
  482.  
  483.         while (fgets(buffer,sizeof(buffer),fvoc)!=NULL) {
  484.  
  485.           if ((ps=strchr(buffer,'\n'))!=NULL)
  486.             *ps='\0';
  487.  
  488.           strncpy(passtest,buffer,NPASS-1);
  489.           str_upr(passtest);
  490.  
  491.           if (!quiet) {
  492.             printf("%-33s",passtest);
  493.             fflush(stdout);
  494.           }
  495.  
  496.           ind_wheel=con_wheel=0;
  497.  
  498.           pre_user=NULL;
  499.           cur_user=first_user;
  500.  
  501.           while (cur_user!=NULL) {
  502.  
  503.             usrdsc.dscw_length=strlen(cur_user->username);
  504.             pwddsc.dscw_length=strlen(passtest);
  505.  
  506.             memcpy(ubuf,cur_user->username,usrdsc.dscw_length+1);
  507.             memcpy(pbuf,passtest          ,pwddsc.dscw_length+1);
  508.  
  509.             usrdsc.dsca_pointer=ubuf;
  510.             pwddsc.dsca_pointer=pbuf;
  511.  
  512.             if ((!quiet) && (!((con_wheel++) & MASKWH)))
  513.               write(1,wheel[ind_wheel=(ind_wheel+1) & 0x3],2);
  514.  
  515.             comparisions++;
  516.  
  517.             lgihpwd(&outdsc,&pwddsc,cur_user->encr_algo1,cur_user->passwd_salt,&usrdsc);
  518.  
  519.             if ((*((dword *)cur_user->passwd1)    ==*((dword *)obuf)) &&
  520.                 (*((dword *)(cur_user->passwd1+4))==*((dword *)(obuf+4)))) {
  521.  
  522.               encryptions++;
  523.  
  524.               fprintf(fout,"User : [%s], Password : [%s]\n",cur_user->username,passtest);
  525.  
  526.               /* delete user from user's list */
  527.  
  528.               if (pre_user==NULL)
  529.                 first_user=cur_user->next;
  530.               else
  531.                 pre_user->next=cur_user->next;
  532.             }
  533.             else
  534.               pre_user=cur_user;
  535.  
  536.             /* next user */
  537.  
  538.             cur_user=cur_user->next;
  539.  
  540.           } /* while */
  541.  
  542.           if (!quiet)
  543.             printf("\bfound: %u\n",encryptions);
  544.  
  545.           memcpy(read_passwd,passtest,pwddsc.dscw_length+1);
  546.  
  547.         } /* while */
  548.  
  549.       } /* for */
  550.  
  551.       end_stat();
  552.  
  553.       if (!quiet)
  554.         print_stat(stdout);
  555.  
  556.       print_stat(fout);
  557.  
  558.       break;
  559.  
  560.     case SINGLE:
  561.  
  562.       print_title(fout);
  563.       str_upr(pass_name);
  564.  
  565.       if (!quiet)
  566.         putchar('\n');
  567.  
  568.       init_stat();
  569.  
  570.       while (fread(&user,sizeof(user),1,fSYSUAF)) {
  571.  
  572.         if (skip || (!((L_Flags_0 *)(&user.Login_Flags_0))->user_account)) {
  573.  
  574.           strip_name(usertest,user.Username,NPASS);
  575.  
  576.           usrdsc.dscw_length=strlen(usertest);
  577.           pwddsc.dscw_length=strlen(pass_name);
  578.  
  579.           memcpy(ubuf,usertest ,usrdsc.dscw_length+1);
  580.           memcpy(pbuf,pass_name,pwddsc.dscw_length+1);
  581.  
  582.           usrdsc.dsca_pointer=ubuf;
  583.           pwddsc.dsca_pointer=pbuf;
  584.  
  585.           if ((!quiet) && (!((con_wheel++) & MASKWH)))
  586.             write(1,wheel[ind_wheel=(ind_wheel+1) & 0x3],2);
  587.  
  588.           num_users++;
  589.           comparisions++;
  590.  
  591.           lgihpwd(&outdsc,&pwddsc,user.Encr_algo1,user.Passwd_salt,&usrdsc);
  592.  
  593.           if ((*((dword *)user.Passwd1)    ==*((dword *)obuf)) &&
  594.               (*((dword *)(user.Passwd1+4))==*((dword *)(obuf+4)))) {
  595.  
  596.             encryptions++;
  597.  
  598.             if (!quiet) {
  599.  
  600.               printf("\bUser : [%s], Password : [%s]\n",usertest,pass_name);
  601.               ind_wheel=con_wheel=0;
  602.             }
  603.  
  604.             fprintf(fout,"User : [%s], Password : [%s]\n",usertest,pass_name);
  605.  
  606.           }
  607.         }
  608.         else
  609.           if (debug) {
  610.  
  611.             strip_name(buffer,user.Username,NPASS);
  612.             printf("\b%s * User account is disabled *\n",buffer);
  613.           }
  614.  
  615.       } /* while */
  616.  
  617.       end_stat();
  618.  
  619.       if (!quiet) {
  620.  
  621.         write(1,"\b ",2);
  622.         print_stat(stdout);
  623.       }
  624.  
  625.       print_stat(fout);
  626.  
  627.       break;
  628.  
  629.     case USER:
  630.  
  631.       print_title(fout);
  632.  
  633.       num_users=1;
  634.  
  635.       usrdsc.dscw_length=strlen(user_name);
  636.  
  637.       if (!quiet)
  638.         putchar('\n');
  639.  
  640.       init_stat();
  641.  
  642.       while (fgets(buffer,sizeof(buffer),fvoc)!=NULL) {
  643.  
  644.         if ((ps=strchr(buffer,'\n'))!=NULL)
  645.           *ps='\0';
  646.  
  647.         strncpy(passtest,buffer,NPASS-1);
  648.         str_upr(passtest);
  649.  
  650.         if (!quiet)
  651.           fputs(passtest,stdout);
  652.  
  653.         pwddsc.dscw_length=strlen(passtest);
  654.  
  655.         memcpy(ubuf,user_name,usrdsc.dscw_length+1);
  656.         memcpy(pbuf,passtest ,pwddsc.dscw_length+1);
  657.  
  658.         usrdsc.dsca_pointer=ubuf;
  659.         pwddsc.dsca_pointer=pbuf;
  660.  
  661.         comparisions++;
  662.  
  663.         lgihpwd(&outdsc,&pwddsc,user.Encr_algo1,user.Passwd_salt,&usrdsc);
  664.  
  665.         if ((*((dword *)user.Passwd1)    ==*((dword *)obuf)) &&
  666.             (*((dword *)(user.Passwd1+4))==*((dword *)(obuf+4)))) {
  667.  
  668.           encryptions++;
  669.  
  670.           fprintf(fout,"User : %s, Password : %s\n",user_name,passtest);
  671.  
  672.           if (!quiet)
  673.             puts(" ** HITTED **");
  674.  
  675.           break;  /* while */
  676.  
  677.         }
  678.  
  679.         if (!quiet)
  680.           putchar('\n');
  681.  
  682.       } /* while */
  683.  
  684.       end_stat();
  685.  
  686.       if (!quiet)
  687.         print_stat(stdout);
  688.  
  689.       print_stat(fout);
  690.  
  691.       break;
  692.  
  693.     case CREATE:
  694.  
  695.       while (fread(&user,sizeof(user),1,fSYSUAF)) {
  696.  
  697.         if (skip || (!((L_Flags_0 *)(&user.Login_Flags_0))->user_account)) {
  698.  
  699.           strip_name(buffer,user.Username,NPASS);
  700.  
  701.           if (debug)
  702.             puts(buffer);
  703.  
  704.           fputs(buffer,fout);
  705.           fputc('\n',fout);
  706.         }
  707.         else {
  708.  
  709.           if (debug) {
  710.  
  711.             strip_name(buffer,user.Username,NPASS);
  712.             printf("%s * User account is disabled *\n",buffer);
  713.           }
  714.         }
  715.       }
  716.  
  717.       break;
  718.  
  719.     case TEST:
  720.  
  721.       puts("Testing encrypted password\n");
  722.  
  723.       printf("  Username: %s  Password: %s  Salt: %04X\n",user_test,passwd_test,SALT_TEST);
  724.  
  725.       for (encrypt=0;encrypt<4;encrypt++) {
  726.  
  727.         switch (encrypt) {
  728.  
  729.           case 0:
  730.  
  731.             puts("\n  AUTODIN-II 32 bit crc code:");
  732.             puts("\n    Algorithms is not currently supported.");
  733.  
  734.             continue; /* FOR */
  735.  
  736.           case 1:
  737.  
  738.             puts("\n  Purdy polynomial over salted input:");
  739.             break;
  740.  
  741.           case 2:
  742.  
  743.             puts("\n  Purdy polynomial + variable length username:");
  744.             break;
  745.  
  746.           case 3:
  747.  
  748.             puts("\n  PURDY_V + additional bit rotation:");
  749.             break;
  750.  
  751.         }
  752.  
  753.         usrdsc.dscw_length=strlen(user_test);
  754.         pwddsc.dscw_length=strlen(passwd_test);
  755.  
  756.         memcpy(ubuf,user_test  ,usrdsc.dscw_length+1);
  757.         memcpy(pbuf,passwd_test,pwddsc.dscw_length+1);
  758.  
  759.         usrdsc.dsca_pointer=ubuf;
  760.         pwddsc.dsca_pointer=pbuf;
  761.  
  762.         lgihpwd(&outdsc,&pwddsc,encrypt,SALT_TEST,&usrdsc);
  763.  
  764.         printf("\n    True     : ");
  765.         print_bytes(hash_test[encrypt],8);
  766.  
  767.         printf("\n    Encrypted: ");
  768.         print_bytes((byte *)obuf,8);
  769.  
  770.         if ((*((dword *)hash_test[encrypt])    !=*((dword *)obuf)) ||
  771.             (*((dword *)(hash_test[encrypt]+4))!=*((dword *)(obuf+4))))
  772.           puts("    TEST ERROR");
  773.         else
  774.           puts("    TEST OK");
  775.  
  776.       } /* for */
  777.  
  778.       break;
  779.  
  780.     case LIST_ALL:
  781.  
  782.       while (fread(&user,sizeof(user),1,fSYSUAF))
  783.         print_record(++num_users);
  784.  
  785.       break;
  786.  
  787.     case LIST_ONE:
  788.  
  789.       print_record(num_users);
  790.  
  791.       break;
  792.  
  793.   } /* switch */
  794.  
  795.   return EXIT_SUCCESS;
  796. }
  797.  
  798. /************************************
  799.  *
  800.  * Print the title of this program
  801.  *
  802.  */
  803.  
  804. void print_title(FILE *f)
  805. {
  806.   char *ps;
  807.  
  808.   if (f!=stdout) {
  809.  
  810.     memset(buffer,'=',77);
  811.     buffer[77]='\0';
  812.  
  813.     fprintf(f,"\n*%s*\n",buffer);
  814.   }
  815.  
  816.   fputs("\nVMS Crack V1.0 security program\n",f);
  817.   fputs("Coded by Davide Casale in June 1994\n",f);
  818.   fputs(" (email address: casale@pmn.it)\n",f);
  819.   fputs("Coded and optimized by Mario Ambrogetti in June 1994\n",f);
  820.   fputs(" (email address: s65710@galileo.polito.it)\n",f);
  821.   fputs("Original algorithm by Shawn Clifford in February 1993\n",f);
  822.   fputs(" (email address : sysop@robot.nuceng.ufl.edu)\n\n",f);
  823.  
  824.   if (f!=stdout) {
  825.  
  826.     switch (opr) {
  827.  
  828.       case VOCABULARY:
  829.  
  830.         ps=str_voca;
  831.         break;
  832.  
  833.       case SINGLE:
  834.  
  835.         ps=str_sing;
  836.         break;
  837.  
  838.       case USER:
  839.  
  840.         ps=str_user;
  841.         break;
  842.     }
  843.  
  844.  
  845.     fprintf(f,"Mode : %s\n",ps);
  846.  
  847.     fprintf(f,"SYSUAF name file : %s\n",SYSUAF_name);
  848.  
  849.     if ((opr==VOCABULARY) || (opr==USER))
  850.       fprintf(f,"Vocabulary name file : %s\n",voc_name);
  851.  
  852.     if (opr==SINGLE)
  853.       fprintf(f,"Password to check : %s\n",pass_name);
  854.  
  855.     if (opr==USER)
  856.       fprintf(f,"Username : %s\n",user_name);
  857.  
  858.     fprintf(f,"Output name file : %s\n",out_name);
  859.     fprintf(f,"\n*%s*\n\n",buffer);
  860.   }
  861.  
  862.   fflush(f);
  863. }
  864.  
  865. /************************************
  866.  *
  867.  * Find a specific user
  868.  *
  869.  */
  870.  
  871. int find_user(char *user_name)
  872. {
  873.   int count=0;
  874.  
  875.   while (fread(&user,sizeof(user),1,fSYSUAF)) {
  876.  
  877.     count++;
  878.  
  879.     strip_name(buffer,user.Username,NPASS);
  880.  
  881.     if (debug)
  882.       puts(buffer);
  883.  
  884.     if (strcmp(buffer,user_name)==0)
  885.       return count;
  886.   }
  887.  
  888.   return 0;
  889. }
  890.  
  891. /************************************
  892.  *
  893.  * Find a specific password
  894.  *
  895.  */
  896.  
  897. int find_passwd(char *passwd)
  898. {
  899.   char *ps;
  900.  
  901.   while (fgets(buffer,sizeof(buffer),fvoc)!=NULL) {
  902.  
  903.     if ((ps=strchr(buffer,'\n'))!=NULL)
  904.       *ps='\0';
  905.  
  906.     str_upr(buffer);
  907.  
  908.     if (strcmp(buffer,passwd)==0)
  909.       return 1;
  910.   }
  911.  
  912.   return 0;
  913. }
  914.  
  915. /*****************************
  916.  *
  917.  * Print user's record
  918.  *
  919.  */
  920.  
  921. void print_record(int num_user)
  922. {
  923.   printf("*%05u*********************************************\n\n",num_user);
  924.  
  925.   printf("Record Header :%04X\n",user.Record_Header);
  926.   printf("Username (loginid) :%.32s\n",user.Username);
  927.   printf("Member UIC :%04X\n",user.Member_UIC);
  928.   printf("Group  UIC :%04X\n",user.Group_UIC);
  929.   printf("Nulls: ");print_bytes(user.Nulls,12);putchar('\n');
  930.   printf("Account name :%.32s\n",user.Account_name);
  931.   printf("Owner :%.*s\n",(int)user.length_owner,user.Owner);
  932.   printf("Device :%.*s\n",(int)user.length_device,user.Device);
  933.   printf("Default (SYS$LOGIN) directory :%.*s\n",(int)user.length_default,user.Default);
  934.   printf("Default login command file :%.*s\n",(int)user.length_command,user.Default_command);
  935.   printf("Default CLI :%.*s\n",(int)user.length_CLI,user.Default_CLI);
  936.   printf("User defined CLI table name :%.*s\n",(int)user.length_CLI_tables,user.User_CLI_table);
  937.   printf("Encrypted primary password   :");print_bytes(user.Passwd1,8);putchar('\n');
  938.   printf("Encrypted secondary password :");print_bytes(user.Passwd2,8);putchar('\n');
  939.   printf("Number of login fails :%u\n",user.Number_login_fails);
  940.   printf("Password encryption salt :%04X\n",user.Passwd_salt);
  941.   printf("Encryption algorithm code - primary password   :%u\n",user.Encr_algo1);
  942.   printf("Encryption algorithm code - secondary password :%u\n",user.Encr_algo2);
  943.   printf("Password minimum length :%u\n",user.Pass_minimum_length);
  944.   printf("Filler :%02X\n",user.Filler1);
  945.   printf("Account expiration date :");print_date(user.Account_ex_date);putchar('\n');
  946.   printf("Password lifetime :");print_date(user.Password_lifetime);putchar('\n');
  947.   printf("Password change date/time - primary password   :");print_date(user.Pass1_change_date);putchar('\n');
  948.   printf("Password change date/time - secondary password :");print_date(user.Pass2_change_date);putchar('\n');
  949.   printf("Last interactive login date/time     :");print_date(user.Last_interactive);putchar('\n');
  950.   printf("Last non interactive login date/time :");print_date(user.Last_non_interactive);putchar('\n');
  951.   printf("Authorize priviledges :");print_bytes(user.Authorize_priviledges,8);putchar('\n');
  952.   printf("Default priviledges   :");print_bytes(user.Default_priviledges,8);putchar('\n');
  953.   printf("Filler :");print_bytes(user.Filler2   ,20);putchar('\n');
  954.   printf("        ");print_bytes(user.Filler2+20,20);putchar('\n');
  955.  
  956.   printf("Login Flags bits byte 0:\n");
  957.  
  958.   printf("  User can not use CTRL-Y :%s\n",AFF(((L_Flags_0 *)(&user.Login_Flags_0))->CTRL_Y));
  959.   printf("  User is restricted to default command interpeter :%s\n",AFF(((L_Flags_0 *)(&user.Login_Flags_0))->default_com));
  960.   printf("  SET PASSWORD command is disabled :%s\n",AFF(((L_Flags_0 *)(&user.Login_Flags_0))->set_pass));
  961.   printf("  Prevent user from changing any defaults at login :%s\n",AFF(((L_Flags_0 *)(&user.Login_Flags_0))->prevent_login));
  962.   printf("  User account is disabled :%s\n",AFF(((L_Flags_0 *)(&user.Login_Flags_0))->user_account));
  963.   printf("  User will not receive the login welcome message :%s\n",AFF(((L_Flags_0 *)(&user.Login_Flags_0))->welcome));
  964.   printf("  Announcement of new mail is suppressed :%s\n",AFF(((L_Flags_0 *)(&user.Login_Flags_0))->new_mail));
  965.   printf("  Mail delivery to user is disabled :%s\n",AFF(((L_Flags_0 *)(&user.Login_Flags_0))->mail_delivery));
  966.  
  967.   printf("Login Flags bits byte 1:\n");
  968.  
  969.   printf("  User is required to use generated passwords :%s\n",AFF(((L_Flags_1 *)(&user.Login_Flags_1))->gen_passed));
  970.   printf("  Primary password is expired   :%s\n",AFF(((L_Flags_1 *)(&user.Login_Flags_1))->primary_pass));
  971.   printf("  Secondary password is expired :%s\n",AFF(((L_Flags_1 *)(&user.Login_Flags_1))->secondary_pass));
  972.   printf("  All actions are audited :%s\n",AFF(((L_Flags_1 *)(&user.Login_Flags_1))->act_audited));
  973.   printf("  User will not receive last login messages :%s\n",AFF(((L_Flags_1 *)(&user.Login_Flags_1))->last_login));
  974.   printf("  User can not reconnect to existing processes :%s\n",AFF(((L_Flags_1 *)(&user.Login_Flags_1))->existing_proc));
  975.   printf("  User can only login to terminals defined by the automatic login facility :%s\n",AFF(((L_Flags_1 *)(&user.Login_Flags_1))->user_login));
  976.   printf("  User is required to change expired passwords :%s\n",AFF(((L_Flags_1 *)(&user.Login_Flags_1))->change_pass));
  977.  
  978.   printf("Login Flags bits byte 2:\n");
  979.  
  980.   printf("  User is restricted to captive account :%s\n",AFF(((L_Flags_2 *)(&user.Login_Flags_2))->captive_acc));
  981.   printf("  Prevent user from executing RUN, MCR commands, or foreign commands :%s\n",AFF(((L_Flags_2 *)(&user.Login_Flags_2))->user_execut));
  982.   printf("  Bits 2-7 Reserved for future use :%02X\n",((L_Flags_2 *)(&user.Login_Flags_2))->future_use);
  983.  
  984.   printf("Login Flags bits byte 3:\n");
  985.  
  986.   printf("  Reserved for future use :%02X\n",user.Login_Flags_3);
  987.  
  988.   printf("Network access bytes - primary days:\n");print_hours(user.Network_primary_days);
  989.   printf("Network access bytes - seconday days:\n");print_hours(user.Network_seconday_days);
  990.   printf("Batch access bytes - primary days:\n");print_hours(user.Batch_primary_days);
  991.   printf("Batch access bytes - seconday days:\n");print_hours(user.Batch_seconday_days);
  992.   printf("Local access bytes - primary days:\n");print_hours(user.Local_primary_days);
  993.   printf("Local access bytes - seconday days:\n");print_hours(user.Local_seconday_days);
  994.   printf("Dialup access bytes - primary days:\n");print_hours(user.Dialup_primary_days);
  995.   printf("Dialup access bytes - secondary days:\n");print_hours(user.Dialup_secondary_days);
  996.   printf("Remote access bytes - primary days:\n");print_hours(user.Remote_primary_days);
  997.   printf("Remote access bytes - seconday days:\n");print_hours(user.Remote_seconday_days);
  998.  
  999.   printf("Filler :");print_bytes(user.Filler3,12);putchar('\n');
  1000.   print_days("Prime days :",user.Prime_days);
  1001.   printf("Filler :%02X\n",user.Filler4);
  1002.   printf("Default base priority :%u\n",user.Default_base_priority);
  1003.   printf("Maximum job queue priority :%u\n",user.Maximum_job_queue_priority);
  1004.   printf("Active process limit :%u\n",user.Active_process_limit);
  1005.   printf("Max. number of interactive, detached, and batch jobs :%u\n",user.Max_number_jobs);
  1006.   printf("Detached process limit :%u\n",user.Detached_process_limit);
  1007.   printf("Subprocess creation limit :%u\n",user.Subprocess_creation_limit);
  1008.   printf("Buffered I/O count :%u\n",user.Buffered_IO_count);
  1009.   printf("Timer queue entry limit :%u\n",user.Timer_queue_entry_limit);
  1010.   printf("AST queue limit :%u\n",user.AST_queue_limit);
  1011.   printf("Lock queue limit :%u\n",user.Lock_queue_limit);
  1012.   printf("Open file limit :%u\n",user.Open_file_limit);
  1013.  
  1014.   printf("Unknown :%u\n",user.unknown1);
  1015.  
  1016.   printf("Shared file limit :%u\n",user.Shared_file_limit);
  1017.   printf("Working set quota :%lu\n",user.Working_set_quota);
  1018.  
  1019.   printf("Unknown :%lu\n",user.unknown2);
  1020.  
  1021.   printf("Working set extent :%lu\n",user.Working_set_extent);
  1022.   printf("Paging file quota :%lu\n",user.Paging_file_quota);
  1023.   printf("Maximum CPU time limit (in 10-milliseconds) :%lu\n",user.Maximum_CPU_time_limit);
  1024.   printf("Buffered I/O byte limit :%lu\n",user.Buffered_IO_byte_limit);
  1025.   printf("Paged buffer I/O byte count limit :%lu\n",user.Paged_buffer_IO_count_limit);
  1026.   printf("Initial byte quota (jobwide logical name table uses) :%lu\n",user.Initial_byte_quota);
  1027.  
  1028.   printf("Filler :");print_bytes(user.Filler5   ,16);putchar('\n');
  1029.   printf("        ");print_bytes(user.Filler5+16,16);putchar('\n');
  1030.   printf("        ");print_bytes(user.Filler5+32,16);putchar('\n');
  1031.   printf("        ");print_bytes(user.Filler5+48,16);putchar('\n');
  1032.  
  1033.   putchar('\n');
  1034. }
  1035.  
  1036.  
  1037. /**************************
  1038.  *
  1039.  * Initialize statistic
  1040.  *
  1041.  */
  1042.  
  1043. void init_stat(void)
  1044. {
  1045.   comparisions=0UL;
  1046.   encryptions=0;
  1047.  
  1048.   time(&start_time);
  1049. }
  1050.  
  1051. /****************************
  1052.  *
  1053.  * End statistic
  1054.  *
  1055.  */
  1056.  
  1057. void end_stat(void)
  1058. {
  1059.   time(&end_time);
  1060.  
  1061.   elapsed=difftime(end_time,start_time);
  1062.  
  1063.   if (elapsed<1.0)
  1064.     elapsed=1.0;
  1065.  
  1066.   report=(double)comparisions/elapsed;
  1067.  
  1068.   if (num_users!=0)
  1069.     performance=((double)encryptions/(double)num_users)*100.0;
  1070.   else
  1071.     performance=0.0;
  1072. }
  1073.  
  1074. /*************************
  1075.  *
  1076.  * Print statistic
  1077.  *
  1078.  */
  1079.  
  1080. void print_stat(FILE *f)
  1081. {
  1082.   if (f!=stdout) {
  1083.  
  1084.     buffer[0]='\n';
  1085.     buffer[1]='*';
  1086.     memset(buffer+2,'=',77);
  1087.     buffer[79]='*';
  1088.     buffer[80]='\n';
  1089.     buffer[81]='\0';
  1090.  
  1091.     fputs(buffer,f);
  1092.   }
  1093.  
  1094. #ifdef __WATCOMC__
  1095.  
  1096.   fputs("\nUsers                  : ",f);
  1097.   utoa(num_users,buffer,10);
  1098.   fputs(buffer,f);
  1099.   putc('\n',f);
  1100.  
  1101.   fputs("Password found         : ",f);
  1102.   utoa(encryptions,buffer,10);
  1103.   fputs(buffer,f);
  1104.   putc('\n',f);
  1105.  
  1106.   fputs("Comparisions           : ",f);
  1107.   ultoa(comparisions,buffer,10);
  1108.   fputs(buffer,f);
  1109.   putc('\n',f);
  1110.  
  1111.   fputs("Time elapsed in seconds: ",f);
  1112.   ultoa((dword)elapsed,buffer,10);
  1113.   fputs(buffer,f);
  1114.   putc('\n',f);
  1115.  
  1116.   fputs("Comparisions/seconds   : ",f);
  1117.   ultoa((dword)report,buffer,10);
  1118.   fputs(buffer,f);
  1119.   putc('.',f);
  1120.   utoa((word)((report-(double)((word)report))*100.0),buffer,10);
  1121.   fputs(buffer,f);
  1122.   putc('\n',f);
  1123.  
  1124.   fputs("Encryption performance : ",f);
  1125.   ultoa((dword)performance,buffer,10);
  1126.   fputs(buffer,f);
  1127.   putc('.',f);
  1128.   utoa((word)((performance-(double)((word)performance))*100.0),buffer,10);
  1129.   fputs(buffer,f);
  1130.   fputs("%\n",f);
  1131.  
  1132. #else
  1133.  
  1134.   fprintf(f,"\nUsers                  : %u\n",num_users);
  1135.   fprintf(f,"Password found         : %u\n",encryptions);
  1136.   fprintf(f,"Comparisons            : %lu\n",comparisions);
  1137.   fprintf(f,"Time elapsed in seconds: %.0f\n",elapsed);
  1138.   fprintf(f,"Comparisons/seconds    : %.2f\n",report);
  1139.   fprintf(f,"Encryption performance : %.2f%%\n",performance);
  1140.  
  1141. #endif  /* __WATCOMC__ */
  1142.  
  1143.   if (f!=stdout) {
  1144.  
  1145.     buffer[0]='\n';
  1146.     buffer[1]='*';
  1147.     memset(buffer+2,'=',77);
  1148.     buffer[79]='*';
  1149.     buffer[80]='\n';
  1150.     buffer[81]='\0';
  1151.  
  1152.     fputs(buffer,f);
  1153.   }
  1154.  
  1155. }
  1156.  
  1157. /**********************************************
  1158.  *
  1159.  * Copy and strip final space from string
  1160.  *
  1161.  */
  1162.  
  1163. void strip_name(char *str,char *name,int num)
  1164. {
  1165.   int i;
  1166.  
  1167.   for (i=0;(i<num) && (*name!=' ');i++)
  1168.     *str++=*name++;
  1169.  
  1170.   *str='\0';
  1171. }
  1172.  
  1173. /******************
  1174.  *
  1175.  * Dump bytes
  1176.  *
  1177.  */
  1178.  
  1179. void print_bytes(byte *bytes,int num)
  1180. {
  1181.   for (;num--;bytes++)
  1182.     printf("%02X ",*bytes);
  1183. }
  1184.  
  1185. /******************
  1186.  *
  1187.  * print data
  1188.  *
  1189.  */
  1190.  
  1191. void print_date(byte *date)
  1192. {
  1193.   print_bytes(date,8);
  1194. }
  1195.  
  1196. /************************
  1197.  *
  1198.  * Print mask hours
  1199.  *
  1200.  */
  1201.  
  1202. void print_hours(byte *byte_hours)
  1203. {
  1204.   register int i;
  1205.  
  1206.   printf("        ");
  1207.  
  1208.   for (i=0;i<24;i++)
  1209.     putchar((byte_hours[i>>3] & (1<<(i & 7)))?'.':'*');
  1210.  
  1211.   putchar('\n');
  1212.  
  1213.   printf("  hours=000000000111111111122222\n");
  1214.   printf("        123456789012345678901234\n");
  1215. }
  1216.  
  1217. /**********************
  1218.  *
  1219.  * Print mask days
  1220.  *
  1221.  */
  1222.  
  1223. void print_days(char *string,byte week)
  1224. {
  1225.   register int i;
  1226.  
  1227.   printf("%s",string);
  1228.  
  1229.   for (i=0;i<7;i++)
  1230.     putchar((week & (1<<i))?'.':'*');
  1231.  
  1232.   puts("\n            MTWTFSS");
  1233. }
  1234.  
  1235. /**********************
  1236.  *
  1237.  * Signal function
  1238.  *
  1239.  */
  1240.  
  1241. static void sgn_fn(void)
  1242. {
  1243.   static const char msg_abort[]="\n** ABORT **\n";
  1244.  
  1245. #ifdef __WATCOMC__
  1246.   signal(SIGBREAK,SIG_IGN);
  1247. #else
  1248.   signal(SIGFPE,SIG_IGN);
  1249. #endif
  1250.  
  1251.   signal(SIGABRT,SIG_IGN);
  1252.   signal(SIGILL ,SIG_IGN);
  1253.   signal(SIGINT ,SIG_IGN);
  1254.   signal(SIGSEGV,SIG_IGN);
  1255.   signal(SIGTERM,SIG_IGN);
  1256.  
  1257.   if(!quiet)
  1258.     fputs(msg_abort,stdout);
  1259.  
  1260.   if ((fout!=NULL) && ((opr==VOCABULARY) || (opr==SINGLE) || (opr==USER))) {
  1261.  
  1262.     end_stat();
  1263.  
  1264.     if (!quiet)
  1265.       print_stat(stdout);
  1266.  
  1267.     fputs(msg_abort,fout);
  1268.  
  1269.     print_stat(fout);
  1270.  
  1271.     fflush(fout);
  1272.  
  1273.  
  1274.   }
  1275.  
  1276.   exit(EXIT_FAILURE);
  1277. }
  1278.  
  1279. /***********************
  1280.  *
  1281.  * Exit function
  1282.  *
  1283.  */
  1284.  
  1285. void exit_fn(void)
  1286. {
  1287.   if (fSYSUAF!=NULL)
  1288.     fclose(fSYSUAF);
  1289.  
  1290.   if (fvoc!=NULL)
  1291.     fclose(fvoc);
  1292.  
  1293.   if (fout!=NULL)
  1294.     fclose(fout);
  1295. }
  1296.  
  1297. /*************************************
  1298.  *
  1299.  * strdup is not ANSI C function
  1300.  *
  1301.  */
  1302.  
  1303. char *str_dup(const char *s)
  1304. {
  1305.   char *ps;
  1306.  
  1307.   if ((ps=(char *)malloc(strlen(s)+1))!=NULL)
  1308.     strcpy(ps,s);
  1309.  
  1310.   return (ps);
  1311. }
  1312.  
  1313. /************************************
  1314.  *
  1315.  * strupr is not ANSI C function
  1316.  *
  1317.  */
  1318.  
  1319. void str_upr(char *s)
  1320. {
  1321.   for(;*s!='\0';s++)
  1322.     *s=toupper(*s);
  1323. }
  1324.